package cn.smartgarden.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.smartgarden.model.Device;
import cn.smartgarden.service.DeviceService;
import cn.smartgarden.service.Utility;
@Controller
@RequestMapping("/device")
public class DeviceController {
	@Autowired
	private DeviceService deviceService;
	
	@RequestMapping(value="/getByargid/{id}",produces={"application/json;charset=utf-8"})
	@ResponseBody
	public String getByargid(@PathVariable("id")String argid){
		Device device =deviceService.selectByArgid(argid);
		Map<String, Object> ret=new HashMap<>();
		if (device!=null) {
			ret.put("status", 1001);
			ret.put("body", device);
		}
		else {
			ret.put("status", 1002);
		}
		return Utility.gson.toJson(ret);
	}
	@RequestMapping(value="/getAll",produces={"application/json;charset=utf-8"})
	@ResponseBody
	public String getAll(){
		List<Device> devices=deviceService.getAll();
		Map<String, Object> ret=new HashMap<>();
		if (devices!=null) {
			ret.put("status", 1001);
			ret.put("body", devices);
		}
		else {
			ret.put("status", 1002);
		}
		return Utility.gson.toJson(ret);
	
	}
}
